<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html >
<html lang="en">
<head>
<%@include file="../common/includeBaseSet.jsp" %>
<%@include file="../common/includeSystemSet.jsp" %>
<%@include file="../common/operation_forbid.jsp" %>
<%@include file="../common/jsVersion.jsp" %>
</head>
<body>
	<div class="page-content">
		    <div class="col-xs-12 panel panel-success" style="height:332px"> 
	         	<div class="col-xs-6" style="width:100%">
	         	    <div class="form-group" style="margin-top:20px">
						<label class="col-xs-2 control-label" style="width:100px;padding-left:40px">标题:</label>
						<input type="text" name="title" id="title" style="width:300px" placeholder="请输入标题  如：市场买入"/>
				     </div>
				     <div class="form-group" style="margin-top:10px">
						<label class="col-xs-2 control-label" style="width:100px">选择文件:</label>
						<input type="text" id="textName" style="width:265px;" placeholder="上传附件" readOnly/> 
	                    <img style="width:30px;cursor:pointer" onclick="callImport('file','textName')" src="${jypath}/resources/images/upload_a.png"/>
	                    <input type="file" style="display:none" onchange="ajaxfile('file')" id="file" name="file"/>
				     </div>
				     <div class="form-group" style="margin-top:10px;text-align:center;">
						<button type="button" onclick="upload('file')" class="btn btn-default">导入</button>
						<button type="button" onclick="excelModel()" class="btn btn-link">模板下载</button>
				     </div>
				     <div class="form-group" style="margin-top:10px;height:65px;">
						<table border="1" style="width:210px;height:50px;float:left">
							<tr>
								<td width="30%" align="center" height="33.33%">客户名称</td>
								<td width="37%" align="center">电话号码</td>
								<td width="33%" align="center">说明</td>
							</tr>
							<tr>
								<td height="33.33%">AAA</td>
								<td>13301701234</td>
								<td>说明1</td>
							</tr>
							<tr>
								<td height="33.33%">BBB</td>
								<td>13401701235</td>
								<td>说明2</td>
							</tr>
						</table>
						<label style="width:250px;float:left;margin-left:15px">
							<font color="red">使用注意：</font><br/>
							1、电话号码为空或格式不正确不予导入<br/>
							2、导入文件必须为excel
						</label>
				     </div>
				     <div id="msg" class="form-group" style="margin-top:10px;border-top:1px solid #d9d9d9;">
						<!-- 导入信息 -->
				     </div>
				 </div>
		    </div>
	</div>	
</body>
<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	
	//导入，触发file点击事件
	function callImport(fileId, textId){ 
	  	var a=document.createEvent("MouseEvents");
	  	a.initEvent("click", true, true);  
	  	document.getElementById(fileId).dispatchEvent(a); 
	} 
	function ajaxfile(fileId){
	  	$("#textName").val($("#"+fileId).val());
	}
	//上传图片
	function upload(fileId){
		var title = $("#title").val();
// 		if(title == ""){
// 			layer.tips('请输入标题', '#title');
// 			return false;
// 		}
		if($("#"+fileId).val() == ""){
			layer.tips('请需要上传的文件', '#textName', {tips:3});
			return false;
		}
		
		layer.load(0, {shade: false}); //弹出加载层
		$.ajaxFileUpload ({
			url:'${jypath}/call/callCustomer/uploadExcel',
			secureuri:false,
			fileElementId:fileId,
			dataType: 'json',
			data:{
		    	 "title":$("#title").val()
		    },
			success: function (data, status) {
				layer.closeAll('loading'); //关闭加载层
				if(data.res == "1"){
					var obj = data.obj.entity;
					
					if(obj.successCount > 0){
						layer.msg("导入成功");
					}else{
						layer.msg("导入失败");
					}
					
					var text = "共"+obj.total+"条<br/>";
						text += "导入成功"+obj.successCount+"条<br/>";
						text += "导入失败"+obj.failCount+"条<br/>";
					if(obj.failCount > 0){
						text += "<a href='${jypath}/call/importError/download?impId="+obj.id+"'>导出错误数据</a>";
					}
					$("#msg").html(text);
					
					//刷新父窗口列表
					parent.getCount();
					parent.getbaseList(1);
				}else{
					layer.msg(data.resMsg);
				}
			}
		});

		$("#textName").val("");
	}
	
	function excelModel(){
		location.href="${callTemplet}";
	}
	
</script>
</html>